package com.zenaprod.zenda.bag;

import com.zenaprod.zenda.config.Config;
import com.zenaprod.zenda.ui.ZendaView;
import com.zenaprod.twodcore.ui.menu.MenuView;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

public class BagView extends MenuView {
    private Config config = Config.getInstance();
    private List<BoxView> boxViews = new ArrayList<BoxView>();


    public BagView(ZendaView parentZendaView, BagModel bagModel, int x, int y, int width, int height) {
        super(parentZendaView, bagModel.getName(), x, y, width, height);
        this.backgroundColor = config.bagMenuFrameBg;

        setX(100);
        setY(50);

        List<Box> boxes = bagModel.getBoxes();

        for (Box box : boxes) {
            BoxView boxView = new BoxView(box, this);
            boxViews.add(boxView);
        }
    }



    public void draw(Graphics2D g2D) {
        super.draw(g2D);

        g2D.setColor(backgroundColor);
//        g2D.drawRect(x, y, width, height);

        for (BoxView boxView : boxViews) {
            boxView.draw(g2D);
        }
    }


    public static Dimension calculateSize(BagModel bagModel) {
        Config config = Config.getInstance();
        int width = (config.boxPerLine + 1) * config.bagPadding + config.boxPerLine * config.boxWidth;
        int height = (bagModel.getRowCount() + 2) * config.bagPadding + (bagModel.getRowCount()+1) * config.boxHeight;
        System.out.println("Width: " + width + ", height: " + height);
        return new Dimension(width, height);
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public void setX(int x) {
        this.x = x;
        this.closeBar.setX(x);
    }

    public void setY(int y) {
        this.y = y;
        this.closeBar.setY(y - closeBar.getHeight());
    }
}
